<?php

namespace App\Http\Controllers\Common;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class FavortieController extends Controller
{
    public function __construct()
    {
        //只有登陆的用户才可以访问此方法。
        $this->middleware('auth');
    }

    public function click(Request $request){

        $model = (new CommentController())->pj_model($request);
//        dd($model->toArray());

        if($favorite = $model->isFavorite(auth()->user())){
            //为真 就收藏了
            $favorite->delete();
        }else{
            //为假 没有收藏过
            $model->favorite()->create(['user_id'=>auth()->id()]);
        }

        return back();
    }



}
